﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using System.IO;

namespace TestDataLoader
{
    class Program
    {
        static void Main(string[] args)
        {
            HtmlDocument hdoc = new HtmlDocument();
            string html = string.Empty;
            using (StreamReader sr = File.OpenText(@"C:\Users\Deepak\Desktop\test\decision.htm"))
            {
                html = sr.ReadToEnd();
                sr.Close();
            }

            hdoc.LoadHtml(html);

            using (TestStoreDataContext dataContext = new TestStoreDataContext())
            {
                List<TestQuestion> testQuestionList = new List<TestQuestion>();
                var mainwords = hdoc.DocumentNode.SelectNodes("//table[@width='445px']");
                foreach (HtmlNode mainword in mainwords)
                {
                    
                    HtmlDocument qdoc = new HtmlDocument();
                    qdoc.LoadHtml(mainword.InnerHtml);
                    var quest = qdoc.DocumentNode.SelectNodes("//span");
                    var answers = qdoc.DocumentNode.SelectNodes("//label");
                    TestQuestion testQuestion = new TestQuestion()
                    {
                        Question = quest[0].InnerHtml,
                        AnsA = answers[0].InnerHtml,
                        AnsB = answers[1].InnerHtml,
                        AnsC = answers[2].InnerHtml,
                        AnsD = answers[3].InnerHtml,
                        SectionID = 143,
                        CorrectAns = "AnsC"
                    };

                    testQuestionList.Add(testQuestion);
                }

                dataContext.TestQuestions.InsertAllOnSubmit(testQuestionList);
                dataContext.SubmitChanges();
            }
        }
    }
}
